package com.pdsu.xpf.graduation01.control;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.pdsu.xpf.graduation01.domain.FeedBack;
import com.pdsu.xpf.graduation01.domain.User;
import com.pdsu.xpf.graduation01.service.impl.AgricultureServiceImpl;
import com.pdsu.xpf.graduation01.service.impl.UserServiceImpl;
import com.pdsu.xpf.graduation01.utils.Result;
import com.pdsu.xpf.graduation01.vo.AgricultureVO;
import com.pdsu.xpf.graduation01.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/user_b")
public class BackUserControl {

    final
    UserServiceImpl userService;
    final
    AgricultureServiceImpl agricultureService;

    public BackUserControl(UserServiceImpl userService, AgricultureServiceImpl agricultureService) {
        this.userService = userService;
        this.agricultureService = agricultureService;
    }

    @ResponseBody
    @RequestMapping("/findAllUser")
    public Result findAllUser() throws JsonProcessingException {
       List<UserVO> users= userService.findAllUserVO();
        return Result.success(users);
    }

    @ResponseBody
    @RequestMapping("/findAllFeedBack")
    public Result findAllFeedBack() throws JsonProcessingException {
        List<FeedBack> feedBacks= userService.findAllFeedBack();
        return Result.success(feedBacks);
    }
    @ResponseBody
    @RequestMapping("/delFeedBackByFID")
    public Result delFeedBackByFID(int fid) throws JsonProcessingException {
       Integer num= userService.delFeedBackByFID(fid);
        return Result.success();
    }
    @ResponseBody
    @RequestMapping("/searchUserByKey")
    public Result searchUserByKey(String key) throws JsonProcessingException {
        List<UserVO> userVOS = userService.searchUserByKey("%"+key+"%");
        return Result.success(userVOS);
    }
    @ResponseBody
    @RequestMapping("/findAllAgricultureVO")
    public Result findAllAgricultureVO() throws JsonProcessingException {
        List<AgricultureVO> agricultureVOS = agricultureService.findAllAgricultureVO();
        System.out.println(agricultureVOS.size());
        return Result.success(agricultureVOS);
    }
    @ResponseBody
    @RequestMapping("/delAgricultureByAID")
    public Result delAgricultureByAID(int aid) throws JsonProcessingException {
        Integer num = agricultureService.delAgricultureByAID(aid);
        return Result.success();
    }
    //delAgricultureByAID
}
